﻿package com.tudou.home.controller.ad
{
    import com.tudou.ad.consts.*;
    import com.tudou.home.commands.*;
    import com.tudou.home.commands.ad.*;
    import com.tudou.home.model.*;
    import com.tudou.home.model.ad.*;
    import org.puremvc.as3.interfaces.*;
    import org.puremvc.as3.patterns.command.*;

    public class AdFrontMultiCommand extends SimpleCommand
    {

        public function AdFrontMultiCommand()
        {
            return;
        }// end function

        override public function execute(param1:INotification) : void
        {
            var _loc_3:int = 0;
            var _loc_2:* = facade.retrieveProxy(AdFrontMultiProxy.NAME) as AdFrontMultiProxy;
            switch(param1.getName())
            {
                case AdFrontMultiCommandSet.START:
                {
                    AdConsts.FRONT_AD_ING = true;
                    _loc_2.init();
                    _loc_3 = _loc_2.getNextAd();
                    nextAd(_loc_3);
                    break;
                }
                case AdFrontMultiCommandSet.COMPLETE:
                {
                    _loc_3 = _loc_2.getNextAd();
                    nextAd(_loc_3);
                    break;
                }
                case AdFrontMultiCommandSet.START_PLAY:
                {
                    _loc_2.skipAds();
                    nextAd(0);
                    break;
                }
                case AdFrontMultiCommandSet.START_LOAD:
                {
                    if (!_loc_2.hasNextAd())
                    {
                        sendNotification(PlayerCommandSet.START_LOAD);
                    }
                    break;
                }
                case AdFrontMultiCommandSet.CLEAR:
                {
                    break;
                }
                case AdFrontMultiCommandSet.TIMEOUT_START_PLAY:
                {
                    if (AdType.PLACARD == _loc_2.nowAd)
                    {
                        sendNotification(AdPlacardCommandSet.TIMEOUT_START_PLAY);
                    }
                    else if (AdType.FRONT == _loc_2.nowAd)
                    {
                        sendNotification(AdFrontCommandSet.TIMEOUT_START_PLAY);
                    }
                    if (AdType.FRONT_LAST == _loc_2.nowAd)
                    {
                        sendNotification(AdFrontLastCommandSet.TIMEOUT_START_PLAY);
                    }
                    else
                    {
                        sendNotification(PlayerCommandSet.START_PLAY);
                    }
                    AdConsts.FRONT_AD_ING = false;
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            return;
        }// end function

        private function nextAd(param1:int) : void
        {
            switch(param1)
            {
                case AdType.FRONT:
                {
                    sendNotification(ExternalCommandSet.ADD_AD_FRONT);
                    sendNotification(AdFrontCommandSet.START);
                    break;
                }
                case AdType.PLACARD:
                {
                    sendNotification(AdPlacardCommandSet.START);
                    break;
                }
                case AdType.FRONT_LAST:
                {
                    sendNotification(ExternalCommandSet.ADD_AD_FRONT_LAST);
                    sendNotification(AdFrontLastCommandSet.START);
                    break;
                }
                default:
                {
                    if (!PageInfo.getInstance().changeItemManual)
                    {
                        sendNotification(PlayerCommandSet.START_PLAY);
                    }
                    AdConsts.FRONT_AD_ING = false;
                    break;
                    break;
                }
            }
            return;
        }// end function

    }
}
